Skip to content

Fix Catalog.is_identical for context-specific messages - #1428

Merged
akx merged 1 commit into
masterfrom
fix-is-identical-context
Nov 4, 2026
Merged

akx merged 1 commit into
masterfrom
fix-is-identical-context

Conversation

@akx

@akx akx commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

is_identical() iterates the internal _messages keys, but looked each one up through Catalog.get(). For a context-specific message that key is a (msgid, msgctxt) tuple, and get() re-runs _key_for() on it, which takes a tuple for a pluralizable message's id and reduces it to msgid alone -- a key no message is stored under. The lookup returned None, so any catalog containing a msgctxt never compared equal, not even to itself.

The visible consequence is that pybabel update --check reports every catalog using pgettext/npgettext as out of date on every run, which makes it unusable as the CI staleness gate it was added for (#831).

Index _messages directly, since the keys being iterated are its own.


Fixes #1307
Closes #1308 (supersedes it)

is_identical() iterates the internal _messages keys, but looked each one
up through Catalog.get(). For a context-specific message that key is a
(msgid, msgctxt) tuple, and get() re-runs _key_for() on it, which takes a
tuple for a pluralizable message's id and reduces it to msgid alone --
a key no message is stored under. The lookup returned None, so any
catalog containing a msgctxt never compared equal, not even to itself.

The visible consequence is that pybabel update --check reports every
catalog using pgettext/npgettext as out of date on every run, which
makes it unusable as the CI staleness gate it was added for (#831).

Index _messages directly, since the keys being iterated are its own.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Aarni Koskela <akx@iki.fi>
@codspeed

codspeed Bot commented Nov 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing fix-is-identical-context (2bbee1c) with master (6f1e45a)

Open in CodSpeed

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.65%. Comparing base (4bda131) to head (2bbee1c).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1428   +/-   ##
=======================================
  Coverage   93.65%   93.65%           
=======================================
  Files          27       27           
  Lines        4962     4964    +2     
=======================================
+ Hits         4647     4649    +2     
  Misses        315      315           
Flag Coverage Δ
macos-14-3.10 92.68% <100.00%> (+<0.01%) ⬆️
macos-14-3.11 92.62% <100.00%> (+<0.01%) ⬆️
macos-14-3.12 92.88% <100.00%> (+<0.01%) ⬆️
macos-14-3.13 92.88% <100.00%> (+<0.01%) ⬆️
macos-14-3.14 92.86% <100.00%> (+<0.01%) ⬆️
macos-14-3.15 92.86% <100.00%> (+<0.01%) ⬆️
macos-14-3.8 92.56% <100.00%> (+<0.01%) ⬆️
macos-14-3.9 92.62% <100.00%> (+<0.01%) ⬆️
macos-14-pypy3.10 92.68% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.10 92.70% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.11 92.64% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.12 92.90% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.13 92.90% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.14 92.88% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.15 92.88% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.8 92.58% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.9 92.64% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-pypy3.10 92.70% <100.00%> (+<0.01%) ⬆️
windows-2022-3.10 92.70% <100.00%> (+<0.01%) ⬆️
windows-2022-3.11 92.63% <100.00%> (+<0.01%) ⬆️
windows-2022-3.12 92.90% <100.00%> (+<0.01%) ⬆️
windows-2022-3.13 92.90% <100.00%> (+<0.01%) ⬆️
windows-2022-3.14 92.88% <100.00%> (+<0.01%) ⬆️
windows-2022-3.15 92.88% <100.00%> (+<0.01%) ⬆️
windows-2022-3.8 92.67% <100.00%> (+<0.01%) ⬆️
windows-2022-3.9 92.63% <100.00%> (+<0.01%) ⬆️
windows-2022-pypy3.10 92.70% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The catalog identity lookup correction is accompanied by regression coverage for contextual singular and pluralizable messages, addressing the reported false staleness behavior.

No open issues 🎉

What changed in this PR

Fixes Catalog.is_identical() for context-specific and pluralizable messages by using stored internal keys directly, preventing false staleness reports from pybabel update --check.

Changes:

  • Corrects contextual message lookup during catalog identity comparisons.
  • Adds regression coverage for contextual singular and pluralizable messages.
File Description
tests/​messages/​test_catalog.py Adds regression coverage for context-specific catalog comparisons.
babel/​messages/​catalog.py Corrects message lookup during catalog identity comparisons.

Review effort: Lite

@akx
akx merged commit 01a520a into master Nov 4, 2026
42 checks passed
@akx
akx deleted the fix-is-identical-context branch November 4, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Catalog.is_identical() is always False when the catalog contains a msgctxt, so pybabel update --check can never pass

3 participants